package feedback.core.services.impl;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import feedback.core.models.entities.Person;
import feedback.core.models.entities.Roler;
import feedback.core.repositories.EntityChangeRepo;
import feedback.core.services.LoginServices;
/**
 * Created by Hien on 5/19/2015.
 */
@Service("loginServices")
public class LoginServicesImpl extends EntityManagerServicesImpl implements LoginServices  {
    @Autowired
    private EntityChangeRepo repo;
   
	@Override
	public Person login(String id, String pass) {
		List<Person> persons = (List<Person>) repo.findByCriteria(Person.class,
                Restrictions.and(
                		Restrictions.or(
                				Restrictions.eq("personNo", id),
                				Restrictions.eq("personMail",id))
                		,
                        Restrictions.eq("personPass", pass)));
        if(persons.size()>0)return persons.get(0);
		return null;
	}

	

	
}
